package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.SiteItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/16 14:38
 * description:
 */
public class BusSiteTvitemAdapter extends RecyclerView.Adapter<BusSiteTvitemAdapter.BusSiteTvitemHolder> {
    private Context mContext;
    private List<QueryNearStandbyRes.BusSiteListBean.BusInfosBean> viewData;
//    private List<QueryNearStandbyRes.BusSiteListBean.BusInfosBean> mList;

    public BusSiteTvitemAdapter(Context mContext) {
        this.mContext = mContext;
//        mList = busInfos;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.site_item;
    }

    @Override
    public BusSiteTvitemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return BusSiteTvitemHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(BusSiteTvitemHolder holder, int position) {
        loadItemData(position, holder.binding);

    }

    private void loadItemData(int position, SiteItemBinding binding) {

        binding.busSiteItemTv.setText(viewData.get(position).getLine_name());
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(List<QueryNearStandbyRes.BusSiteListBean.BusInfosBean> viewData) {
        this.viewData = viewData;
    }

    public static class BusSiteTvitemHolder extends RecyclerView.ViewHolder {
        private SiteItemBinding binding;

        public static BusSiteTvitemHolder creat(ViewGroup parent) {

            SiteItemBinding binding = SiteItemBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new BusSiteTvitemHolder(binding);
        }

        public BusSiteTvitemHolder(SiteItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
